import logging
import time

from tools.base_page import BasePage, Base_Api


class Test_Fx_flow(BasePage):
    def folw_query(self):  # 流程查询

        name = self.find(self.only_read_yaml('../data/fx_flow_manage.yaml', 'first_name')).text
        author_name = self.find(self.only_read_yaml('../data/fx_flow_manage.yaml', 'first_author_name')).text
        self.open_yaml_element('../data/fx_flow_manage.yaml', 'lc_name', content=name)
        self.open_yaml_element('../data/fx_flow_manage.yaml', 'lc_author_name', content=author_name)
        self.open_yaml_element('../data/fx_flow_manage.yaml', 'query_locator')
        self.screen('分析流程管理列表')
        return self.find(self.only_read_yaml('../data/fx_flow_manage.yaml', 'query_total')).text

    def uitest_news_flow(self,lc_name):
        self.open_yaml_element('../data/fx_flow_manage.yaml','news_locator')

        self.open_yaml_element('../data/fx_flow_manage.yaml','design_type')  # 设计类型第一个
        design_type_option = self.only_read_yaml('../data/fx_flow_manage.yaml','design_type_option')

        self.selector_execute_script(design_type_option[1])  # 选择设计类型中的选项

        self.open_yaml_element('../data/fx_flow_manage.yaml','design_type_two')
        design_type_option_two = self.only_read_yaml('../data/fx_flow_manage.yaml','design_type_option_two')
        time.sleep(1)
        self.selector_execute_script(design_type_option_two[1])
        lc_name_locator = self.elements(('css selector','.ant-input'))
        lc_name_locator[2].send_keys(lc_name)

        use_locator = self.only_read_yaml('../data/fx_flow_manage.yaml','use_locator')
        self.selector_execute_script(use_locator[1])
        return self


    def template_export(self,lc_name,mb_name,describe): # 模板输出
        '''
        :param lc_name:  流程名称
        :param mb_name:  模板名称
        :param describe:   模板描述
        :return: True 作为断言依据
        '''
        self.uitest_news_flow(lc_name)
        tools_options = self.open_yaml_element('../data/fx_flow_manage.yaml','tools_options',is_elements=1,ele_num=2) # 模板输出

        self.open_yaml_element('../data/fx_flow_manage.yaml','lczhuanmb',is_elements=1,ele_num=2) # 研究类型
        self.selector_execute_script(self.only_read_yaml('../data/fx_flow_manage.yaml','lczhuanmb_option')[1])

        self.open_yaml_element('../data/fx_flow_manage.yaml','lczhuanmb',is_elements=1,ele_num=3) # 设计类型
        self.selector_execute_script(self.only_read_yaml('../data/fx_flow_manage.yaml','lczhuanmb_option_two')[1])

        self.open_yaml_element('../data/fx_flow_manage.yaml','lczhuanmb_name',is_elements=1,ele_num=1,content=mb_name)  # 模板名称
        self.open_yaml_element('../data/fx_flow_manage.yaml','lczhuanmb_describe',is_elements=1,ele_num=0,content=describe)  # 模板描述
        self.open_yaml_element('../data/fx_flow_manage.yaml','confirm_locator')  #  确定
        return True

    def lc_save(self,lc_name):
        self.uitest_news_flow(lc_name)
        self.open_yaml_element('../data/fx_flow_manage.yaml','tools_options',is_elements=1,ele_num=3) # 保存
        self.open_yaml_element('../data/fx_flow_manage.yaml','tools_options',is_elements=1,ele_num=6) # 返回
        return self.folw_query()  # 返回查询数量

